package YuanFuDao2;

/**
 * 用二分法对一个数字开根号
 */
public class Main28 {
    public static void main(String[] args) {
        System.out.println(sqrt(5));
    }

    public static float sqrt(int x){
        float low = 0;
        float high = x;
        while(low <= high){
            float mid = low + (high - low) / 2;
            if(mid*mid == x){
                return mid;
            }else if(mid*mid > x){
                high = mid;
            }else{
                low = mid;
            }
        }
        return high;
    }

}
